package com.example.demo.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.entity.Competition;
import com.example.demo.service.DcMainService;

@Controller
public class CompDcNewController {
@Autowired
	private DcMainService dcMainService;
@RequestMapping("/NewCompetition")
 public ModelAndView newCompetition(@RequestParam("OrganizersName") String organizersName,
			@RequestParam("CompetitionName") String competitionName,
			@RequestParam("CompetitionType") String competitionType,
			@RequestParam("CompetitionDate") String competitionDate,
			@RequestParam("CompetitionPrice") String competitionPrice,
			@RequestParam("CompetitionRemarks") String competitionRemarks,Model model,@RequestParam String action) {
	 			Competition competition=new Competition();
	 				if(action.equals("创建")) {
	 				if(organizersName!=null&&competitionName!=null&&competitionType!=null&&
	 						competitionDate!=null&&competitionPrice!=null) {
	 						String competitionStatus="未审批";
	 						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	 						String CreateTime=sdf.format(new Date());
dcMainService.newCompetition(organizersName, competitionName, competitionType, competitionDate, competitionPrice,competitionRemarks,competitionStatus,CreateTime);
	 						competition.setCompetitionStatus(competitionStatus);
	 						competition.setCT(CreateTime);
	 						competition.setCompetitionDate(competitionDate);
	 						competition.setCompetitionName(competitionName);
	 						competition.setCompetitionPrice(competitionPrice);
	 						competition.setCompetitionRemarks(competitionRemarks);
	 						competition.setCompetitionType(competitionType);
	 						competition.setOrganizersName(organizersName);
	 																	}
	 						ModelAndView mv=new ModelAndView();
	 						mv.setViewName("CompDcPay.html");
	 						mv.addObject(competition);
	 						return mv;
	 				}
	 					ModelAndView mav=new ModelAndView();
						mav.setViewName("CompDcMain.html");
	 					return mav;
 							}
}
